package com.richman.isn;


import java.awt.Color;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Date;
import java.util.Stack;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.StringEntity;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

import org.json.*;



import java.util.Vector;
import java.util.Comparator;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
//
//import javax.xml.parsers.DocumentBuilder;  
//import javax.xml.parsers.DocumentBuilderFactory;  
//  
//
//
//import org.w3c.dom.Document;  
//import org.w3c.dom.Element;  
//import org.w3c.dom.NodeList;

import com.richman.controller.DecreaseRatioClient;
import com.richman.ps38.entity.BetAdyData;
import com.richman.ps38.entity.HGEvent;
import com.richman.utils.Common;



//import org.w3c.dom.Node;


public class ISNHttp {

	CloseableHttpClient httpclient = null;
	RequestConfig requestConfig = null;
	HttpClientContext clientContext = null;
	
	long canGetBalanceTime = -1;
	
 	public long getCanGetBalanceTime() {
		return canGetBalanceTime;
	}
	
	int defaultTimeout = 60*1000;
	
	 {
		 
		 HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");
		 
	    requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
	    requestConfig = RequestConfig.copy(requestConfig).setRedirectsEnabled(false).build();//禁止重定向 ， 以便获取cookieb18
	    
	   // requestConfig = RequestConfig.copy(requestConfig).setProxy(proxy).build();//使用代理
	    
	    requestConfig = RequestConfig.copy(requestConfig).setConnectTimeout(defaultTimeout).setConnectionRequestTimeout(defaultTimeout).setSocketTimeout(defaultTimeout).build();//设置超时
	        httpclient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
	 }
	
	 
	 
	 
	 String[] blackboxarry = {"0400AKHeWb1CT4UHcCiyOFFxUJs9WruPWg2xwTpqC7aOF/G7cVE#xxeTH9qn7gvBN1hODpQyKLUtdcy/gVjxK6YQUmuthzD1rRD5A9buc5roGxhe#J5xbAcO8rvcbfkqJhb4bZWp/5NFsh3QANolZLufCAU8wqwM/zbpaoaJowy5lsfph/T#lMlRTFuxuMBV69L9DJ0qCc4gMpergecSo06izT8HnO#s8lyWpM5YbymrVY7rLMnUY2Yy4xZkFqaUZegb#KaePAdj0dC1DOkZ9ybRxHxfYV3WeA0UYsMZmVY5fSPUN2oHNYZpt1ozpn47xUgPTMj6Y82LrlflYU9iUMb03YzV7IDBIIRtgx5t4CWwXewJB/s4Mwp5btF9#kXk6jWRn9G0Cffid9KqGO3oLohutw1/InDlj2XMuF6OiUfqPLjYdgXmjJkcl5haIlLY6FnWC1qHoGk5NgOHQJG3PEGJQEF/V33vgKI2yAfUMZ5LKFpDFK356A5kn36mAJ3ZTHu23WaFMcpDuPLLCLfgMB41yXjhWeZaUwkKrI3MaSYrgzuOZTYvnKL0JQQ08ROukpTpxifyrThRovESnjwNVGXSgGQ8InPsuf6/kpMgG84gzO5PMQF00uJew9XqxzJ4y#q4mStCxJ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SRRYaqhKKhmTNPWCy4nJzQCugKVOTcKUJixNc9QoXJB6xfRWCqp0tokzUp0K#OKLn0OAhXJ9AFUmoq3MFE1OVZYIN0TiGh2ocxF8rf4jemlekKDk9nbjLKqMlA4FJr4dyXapdkDIJTQkZrrm8#sZ"
	 };	


	 String chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890";


	

	private int statusCode = -1;
	
	
	
    Vector<Long> lastTenRequestTime = new Vector<Long>();
    long avgRequestTime = 0;    
    boolean bcalcRequestTime = true;
    boolean bneedChangeLine = false;
   
   
    long lastChangeLineTime = 0;
   
    String strCookies = "";
   
    int requestFailTimes = 0;
    long lastFailtime = 0;
   
    boolean isNeedRelogin = false;
   
    public boolean isInRelogin = false;
    
	 String ADDRESS = "";
	 String ACCOUNT = "";
	 String PWD = "";
	 String SECURITYCODE = "";
	 
	 String user_id = "";
	 String mtype = "3";
	 String cid = "";
	 int time_zone = 0;
	 
	 boolean bLogin = false;
	
	 
	  Vector<String> showLeagueName = new Vector<String>();
	 
    private  ReadWriteLock lockeFinalEventsDetails = new ReentrantReadWriteLock();
    
    private  ReadWriteLock lockeSuccessTime = new ReentrantReadWriteLock();
    
    
    private  ReadWriteLock inplaydxqgameslock = new ReentrantReadWriteLock();
    
    
    public  Vector<String[]> finalEventDetailsVec = new Vector<String[]>();

    public  String successTime = "";
	 
    
    public long canLoginTime = 0;
    int slowDownTimes = 1;
    String token = "";
    
    
    public int getStatusCode() {
   	 
   	 
   	 
   	 return statusCode;
    }
    
    // 1成功	 -1登录失败, -2维护 , -3账号异常 , -4密码不正确 , 2抓取成功, 3抓取失败
    public void updateStatusCode(int i) {
    	
    	if(i == 1) {
    		DecreaseRatioClient.mainWnd.updateMainWndSpecialHGStatusText(1,  "在线");
    	}

    	if(i == -4) {
    		DecreaseRatioClient.mainWnd.updateMainWndSpecialHGStatusText(0,  "无法登录");
    	}
    	
    	if(i == -1) {
    		DecreaseRatioClient.mainWnd.updateMainWndSpecialHGStatusText(0,  "掉线");
    	}

    	//Common.logOut(ACCOUNT + "  update hg_statusCode from " +   Integer.toString(statusCode) + " to " + Integer.toString(i));
    	
   	 statusCode = i;
    
    }
    
    
    public long getCanLoginTime() {
   	 return canLoginTime;
    }
    
    
    
    
	public  void initShowLeagueName(){
		showLeagueName.add("德国 - 德甲");
		showLeagueName.add("欧足联 - 冠军联赛");
		showLeagueName.add("西班牙 - 西甲");
		showLeagueName.add("意大利 - 甲级联赛");
		showLeagueName.add("法国 - 甲级联赛");
		showLeagueName.add("英格兰 - 超级联赛");
		showLeagueName.add("欧足联 - 欧罗巴联赛");
	}
	
	
	public void clearuser_id(){
		user_id = "";
	}
	
	public void setAddress(String address){
		ADDRESS = address;
	}
	

	
	
	
	
	public   boolean isInShowLeagueName(String str){
		boolean in = false;
		
		for(int i = 0; i < showLeagueName.size(); i++){
			if(showLeagueName.elementAt(i).contains(str)){
				in = true;
				break;
			}
		}
		
		return in;
	}
    
    
	public  void setGrabStext(String str){

		SimpleDateFormat df = new SimpleDateFormat("MM-dd HH:mm:ss");// 设置日期格式
		
		String timeStr = df.format(System.currentTimeMillis());

		//gamedetailswnd.setStateText(timeStr + ":" + str);

	}
	
	public  void setGrabColor(Color cr){
		
		//gamedetailswnd.setStateColor(cr);
	
	}
	
	
    

	
	
	
    
    
    public  void copyTofinalEventsDetails(){
    	
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");// 设置日期格式
		
		
		long currentTimeL = System.currentTimeMillis();
    	
		String currentTime = df.format(currentTimeL);
    	
    	lockeFinalEventsDetails.writeLock().lock();
    	
    	if(finalEventDetailsVec.size() != 0){
    		finalEventDetailsVec.clear();
    	}
    	
//    	for(int i = 0; i < eventDetailsVec.size(); i++ ){
//    		finalEventDetailsVec.add(eventDetailsVec.elementAt(i).clone());
//    	}

    	
    	lockeFinalEventsDetails.writeLock().unlock();
    	
    	lockeSuccessTime.writeLock().lock();
    	successTime = currentTime + " 成功";
    	lockeSuccessTime.writeLock().unlock();
    }
    
    
    public  Vector<String[]> getFinalEventsDetails(){
    	Vector<String[]> vec = new Vector<String[]>();
    	lockeFinalEventsDetails.readLock().lock();
    	
    	for(int i = 0; i < finalEventDetailsVec.size(); i++){
    		vec.add(finalEventDetailsVec.elementAt(i).clone());
    	}
    	
    	//vec = (Vector<String[]>)finalEventDetailsVec.clone();
    	lockeFinalEventsDetails.readLock().unlock();
    	return vec;
    }
    
    
    public  String getSuccessTime(){
    	String successTimetmp = "";
    	lockeSuccessTime.readLock().lock();
    	successTimetmp = successTime;
    	lockeSuccessTime.readLock().unlock();
    	return successTimetmp;
    }

	 
	 

	
	
	
	
	public String getAccount(){
		return ACCOUNT;
	}
    
    
	public boolean islogin(){
		return bLogin;
	}	 
	
	public void setIslogin(boolean b){
		bLogin = b;
	}
	
	public  void setLoginParams(String address, String account, String pwd){
		ADDRESS = address;
		ACCOUNT = account;
		PWD = pwd;
	}
	
	

    public int login(){// 1成功	 -1登录失败, -2维护 , -3账号异常, -4密码不正确  -5慢点再登录
    	
    	String res = "";
    	
    	try{
    		
        	String loginLine = ADDRESS + "membersite-api/api/member/authenticate"; 
			JSONObject jb = new JSONObject();
        	jb.put("username", ACCOUNT);
        	jb.put("password", PWD);
        	
        	//Common.logOut(jb.toString());
        	
        	res = doPost(loginLine, jb.toString(), "");
        	
        	
        	if(res == null) {
        		return -1;
        	}
        	
        	JSONObject jbres = new JSONObject(res);
        	
        	if(res.contains("\"errorCode\":\"429\"")||res.contains("lease slow down")) {
        		Common.logOut("请求过多，慢下来");
        		canLoginTime = System.currentTimeMillis() + slowDownTimes*30*1000;
        		slowDownTimes = slowDownTimes+1;
        		updateStatusCode(-1);
        		return -1;
        	}
        	
        	if(jbres.getBoolean("success") == true) {     
        		token = jbres.getString("token");
        		updateStatusCode(1);
        		slowDownTimes = 1;
        		return 1;
        	}
        	
        	if(jbres.getString("responseMessage").contains("密码不正确")) {
        		updateStatusCode(-4);
        		return -4;
        	}
        	
        	updateStatusCode(-1);
        	return -1;
        	
        	
    		
    	}catch(Exception e){
    		e.printStackTrace();
    		if(!res.contains("Site is under maintenance")) {
    			Common.logOut("错误的res；" +res);
    		}
    		
    		
    	}
    	
    	updateStatusCode(-1);
    	
    	return -1;
    }
    
    
    public void getBalance() {
    	
    	try{
        	String url = ADDRESS + "membersite-api/api/member/info?_=" + Long.toString(System.currentTimeMillis());
        	String res = doGet(url, "", "", token);
        	if(res != null && res.contains("betCredit")) {
        		JSONObject jb = new JSONObject(res);
        		double balance = jb.getDouble("betCredit");
        		DecreaseRatioClient.mainWnd.updateISNAccountBalance(ACCOUNT, Double.toString(balance));
        		canGetBalanceTime = System.currentTimeMillis() + 30*1000;
        		DecreaseRatioClient.mainWnd.updateMainWndSpecialHGStatusText(1,  "在线");
        	}else {
        		Common.logOut("ISN getBalance");
        		Common.logOut(res);
        		updateStatusCode(-1);
        	}
    	}catch(Exception e) {
    		updateStatusCode(-1);
    		e.printStackTrace();
    	}
    	

    	
    }
  

    public  CloseableHttpResponse  execute(HttpUriRequest request) throws IOException, ClientProtocolException{
    	
    	long time1 = System.currentTimeMillis();
    	long time2 = System.currentTimeMillis();
    	
    	CloseableHttpResponse response;
    	
    	
    	SimpleDateFormat dfsec = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	
    	
    	try{
    		Thread.sleep(100);
    		//Thread.sleep(1200);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    	
    	
    	
    	
    	//Common.logOut("excecute time:" + dfsec.format(time1));
    	
    	
    	try{
    		response = httpclient.execute(request);    		
    		time2 = System.currentTimeMillis();    		
    		calcRequestAveTime(time2 - time1);
    		
    	}catch(Exception e){
    		
    		time2 = System.currentTimeMillis();
    		calcRequestAveTime(time2 - time1);
    		
    		throw e;
    	}
    	

    	
    	return response;
    	
    }
    
    
    public String doGet(String url, String cookies, String referUrl, String token) {
    	
        try {  
            // 创建httpget.    
            HttpGet httpget = new HttpGet(url);
            
            if(cookies != "") {
            	httpget.addHeader("Cookie",cookies);
            }
            httpget.addHeader("Accept-Encoding","Accept-Encoding: gzip, deflate, sdch");
            httpget.addHeader("Accept-Language","Accept-Language: zh-CN,zh;q=0.8");
            httpget.addHeader("Connection","keep-alive");
            httpget.addHeader("locale","zh_CN");
            httpget.addHeader("Upgrade-Insecure-Requests","1");
            httpget.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
            if(token.length() > 0) {
            	httpget.addHeader("Authorization","Bearer " + token);
            }
            //
            
            if(referUrl != "")
            {
            	httpget.addHeader("Referer",referUrl);
            	
            }
            
            httpget.addHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36");           
           // Common.logOut("executing request " + httpget.getURI()); 
           
            //设置超时
            
//            HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");
//            
//            RequestConfig requestConfigtmp = RequestConfig.custom().setSocketTimeout(defaultTimeout).setConnectTimeout(defaultTimeout).build();
//            requestConfigtmp= RequestConfig.copy(requestConfigtmp).setProxy(proxy).build();
//            httpget.setConfig(requestConfigtmp);
            
            // 执行get请求.    
            CloseableHttpResponse response = execute(httpget); 
            
            String statusLine = response.getStatusLine().toString();   
            if(statusLine.indexOf("200 OK") == -1) {
         	  // Common.logOut(statusLine); 
            }
            
            try{
            	setCookie(response);  	
            	//Common.logOut("设置cookie:" + strCookies);
            	
            	if(response.getStatusLine().toString().indexOf("302 Found") > 0) {
             	   return response.getFirstHeader("Location").getValue();
                }
                HttpEntity entity = response.getEntity(); 
                
                String res = EntityUtils.toString(entity);
                
                if(res != null && res.length() > 0 ){     
                	//Common.logOut(res);
                	
//                	if(res.contains("logout_warn")) {
//                		updateStatusCode(-1);
//                	}
                	
                    return res;
                }
            }finally{
                httpget.releaseConnection();
                response.close();
            }
            

            

        } catch (ClientProtocolException e) {  
            e.printStackTrace(); 
        } catch (ParseException e) {  
            e.printStackTrace(); 
        } catch (IOException e) {  
            e.printStackTrace(); 
        } catch (Exception e){
        	e.printStackTrace();
        }
        
        return null;
    }
    
    
    
    /**以utf-8形式读取*/
    public String doPost(String url,String formparams, String token) {
        return doPost(url, formparams,"UTF-8", token);
    }

    public String doPost(String url,String formparams,String charset, String token) {


     // 创建httppost   
    	
    	try {
    	
        HttpPost httppost = new HttpPost(url); 
        
/*        if(url.contains("get_today_ft_league_wager.php")){
        	httppost.addHeader("Cookie", strCookies);
        }*/
        
        //httppost.addHeader("Cookie", cookies);
        //httppost.addHeader("Accept-Encoding","Accept-Encoding: gzip, deflate, sdch");
        //httppost.addHeader("x-requested-with","XMLHttpRequest");
        //httppost.addHeader("Accept-Language","Accept-Language: zh-CN");
        httppost.addHeader("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
        httppost.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
        httppost.addHeader("Content-type", "application/json");
        httppost.addHeader("Accept-Encoding","gzip, deflate");
        httppost.addHeader("Connection","keep-alive");
        httppost.addHeader("Cache-Control","max-age=0");
        httppost.addHeader("locale","zh_CN");
        httppost.addHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36");    

        if(!token.equals("")) {
        	httppost.addHeader("Authorization","Bearer " + token);
        }

        StringEntity requestEntity = new StringEntity(formparams,"utf-8");

           requestEntity.setContentEncoding("UTF-8");
           httppost.setEntity(requestEntity);


            
            
            
//            HttpHost proxy = new HttpHost("127.0.0.1", 1080, "http");
//            
//
//            
//            
//            
//            RequestConfig requestConfigtmp = RequestConfig.custom().setSocketTimeout(defaultTimeout).setConnectTimeout(defaultTimeout).build();
//            requestConfigtmp= RequestConfig.copy(requestConfigtmp).setProxy(proxy).build();
//            httppost.setConfig(requestConfigtmp);
            
            CloseableHttpResponse response = execute(httppost);
            try {
                // 打印响应状态    
            	setCookie(response);
            	//Common.logOut("设置cookie:" + strCookies);
            	if(response.getStatusLine().toString().indexOf("302 Found") > 0) {
            		String location = response.getFirstHeader("Location").getValue();
            		//Common.logOut(response.getStatusLine());
            		
            		
            		
            		if(location != null) {
            			return location;
            		}
            	}
            	
            	
            	
            	//Header headers[] = response.getHeaders("Content-Type");
            	
            	
                HttpEntity entity = response.getEntity(); 
                
                String res = "";
                
                if(url.contains("get_today_ft_league_wager.php") || url.contains("app/ft/get_today_ft_allbets_wager.php")){            		
                	res = new  String(EntityUtils.toString(entity).getBytes("ISO-8859-1"), "UTF-8");
                }else{
                	res = EntityUtils.toString(entity);
                }
                
                
                if(res != null && res.length() > 0 ){   

//                	if(res.contains("logout_warn")) {
//                		updateStatusCode(-1);
//                	}
                	
                	//Common.logOut(res);
                    return res;
                }
            	
            	

            } finally {  
            	httppost.releaseConnection();
                response.close(); 
            }  
        } catch (ClientProtocolException e) {  
            e.printStackTrace(); 
        } catch (UnsupportedEncodingException e1) {  
            e1.printStackTrace(); 
        } catch (IOException e) {  
            e.printStackTrace(); 
     
        } catch(Exception e){
     	   e.printStackTrace();
        } 
        return null;
    }
    
    
    
	public String setCookie(CloseableHttpResponse httpResponse)
	{
		//strCookies = "";
		//Common.logOut("----setCookieStore");
		Header headers[] = httpResponse.getHeaders("Set-Cookie");
		if (headers == null || headers.length==0)
		{
			//Common.logOut("----there are no cookies");
			return null;
		}

		String cookie = "";
		for (int i = 0; i < headers.length; i++) {
			cookie += headers[i].getValue();
			if(i != headers.length-1)
			{
				cookie += ";";
			}
		}
		String cookies[] = cookie.split(";");
		
		for (String c : cookies)
		{
			if(c.indexOf("path=") != -1 || c.indexOf("expires=") != -1 || c.indexOf("domain=") != -1 || c.indexOf("HttpOnly") != -1)
				continue;
			strCookies += c;
			strCookies += ";";
		}
		//Common.logOut("----setCookieStore success");

		return strCookies;
	}
    
    
    public synchronized void calcRequestAveTime(long requestTime){
        
    	if(bcalcRequestTime == true){
    		
        	//requestCount++;
        	
    		long totalReqeustTime = 0;
    		
        	lastTenRequestTime.add(requestTime);
        	
        	while(lastTenRequestTime.size() >10){
        		lastTenRequestTime.remove(0);
        	}
        	
        	
        	if(lastTenRequestTime.size() == 10){
            	for(int i = 0; i < lastTenRequestTime.size(); i++){
            		totalReqeustTime += lastTenRequestTime.elementAt(i);
            	}
            	avgRequestTime = totalReqeustTime/lastTenRequestTime.size();
            	
            	
            	//System.out.printf("[迪斯尼会员]平均请求时间:%d\n", avgRequestTime);
            	
            	
            	long currentTime = System.currentTimeMillis();
            	
            	long passTime = currentTime - lastChangeLineTime;
            	
            	if(avgRequestTime >= 500 && passTime >= 90*1000){
            		//setisNeedChangeLine(true);
            		lastChangeLineTime = currentTime;
            	}

        	}

    	}

    		
    	
    }
    
    public String getOutlineData() {
    	
    	try {
    		
        	String url = ADDRESS + "membersite-api/api/statement/periods?_=" + Long.toString(System.currentTimeMillis());
        	String res = doGet(url, "", "", token);
        	String latestMonth = "";
        	if(res != null && res.contains("[")) {
        		res = res.replace("[", "");
        		res = res.replace("]", "");
        		String[] monthArr = res.split(",");
        		latestMonth = monthArr[monthArr.length-1];
        		latestMonth = latestMonth.replace("\"", "");
        		
        	}
        	
        	if(latestMonth.length() > 0) {
        		url = ADDRESS + "membersite-api/api/statement/list/" + latestMonth  + "?="+ Long.toString(System.currentTimeMillis());
        		res = doGet(url, "", "", token);
        		if(res != null && res.contains("[")) {
        			return res;
        		}
        	}
        	
        	return null;
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    	}
    	
    	return null;
    	
    	//http://isn99.com/membersite-api/api/statement/periods?_=1573797273989
    }
    
	public String getDetailsData(String datetime) {
    	try {
    		
        	String url = ADDRESS + "membersite-api/api/statement/bets/" + datetime + "?=" + Long.toString(System.currentTimeMillis());
        	String res = doGet(url, "", "", token);
        	
        	if(res != null && res.contains("[")) {
        		return res;
        		
        	}

        	return null;
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    	}
    	
    	return null;
	}
    
	
	public JSONObject getISNEvents() {
		try {
    		String inplayUrl = ADDRESS + "membersite-api/api/data/events/1/3/0/4/3?_=" + Long.toString(System.currentTimeMillis()); 
    		String res = doGet(inplayUrl, "", "", token);
    		
    		if(res == null) {
    			res = doGet(inplayUrl, "", "", token);
    		}
    		
    		if(res != null && res.contains("schedule")) {
    			JSONObject inplayRes = new JSONObject(res);
    			return inplayRes;
    		}
    		
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	
	
	
	
    public Map<String,String> dobet(String homeTeam, String awayTeam, String updown, String bettype, int gold, Double pankouarg,double ratio, int inrecursiontimes) {
    	
    	//JSONObject returnRes = new JSONObject();
    	
    	Map<String, String> map = new HashMap<String, String>();
    	    	   
    	try {
    		
    		String eventsUrl = ADDRESS + "membersite-api/api/data/events/1/3/0/4/3?_=" + Long.toString(System.currentTimeMillis());    	
    		if(bettype.contains("单式")) {
    			eventsUrl = ADDRESS + "membersite-api/api/data/events/1/2/0/4/3?_=" + Long.toString(System.currentTimeMillis());
    		}
    		String res = doGet(eventsUrl, "", "", token);    		
    		if(res == null) {
    			res = doGet(eventsUrl, "", "", token);
    		}    		
    		String marketName = "";
    		if(bettype.contains("单式")&&bettype.contains("让球")) {
    			marketName = "让球";
    		}else if(bettype.contains("滚球")&&bettype.contains("让球")) {
    			marketName = "滚球让球";
    		}else if(bettype.contains("单式")&&bettype.contains("全场大小")) {
    			marketName = "大小";
    		}else if(bettype.contains("单式")&&bettype.contains("半场大小")) {
    			marketName = "半场大小";
    		}else if(bettype.contains("滚球")&&bettype.contains("全场大小")) {
    			marketName = "滚球大小";
    		}else if(bettype.contains("滚球")&&bettype.contains("半场大小")) {
    			marketName = "半场滚球大小";
    		}
    		
    		String betIndicator = "Home";
    		
    		if(bettype.contains("让球")) {
    			if(updown.equals("1")) {
        			betIndicator = "Home";
        		}else {
        			betIndicator = "Away";
        		}
    		}else if(bettype.contains("大小")) {
    			if(updown.equals("1")) {
        			betIndicator = "Over";
        		}else {
        			betIndicator = "Under";
        		}
    		}
    		
    		
    		
    		
    		
    		if(res != null && res.contains("schedule")) {
    			JSONObject inplayRes = new JSONObject(res);
    			JSONArray leagues = inplayRes.getJSONObject("schedule").getJSONArray("leagues");
    			//遍历jsonarray
    			JSONObject event = null;
    			boolean find = false;
    			for(int i = 0; i< leagues.length(); i++) {
    				JSONObject league = leagues.getJSONObject(i);
    				JSONArray events = league.getJSONArray("events");
    				for(int j = 0 ; j < events.length(); j++) {
    					event = events.getJSONObject(j);
    					if(event.getString("homeTeam").equals(homeTeam) && event.getString("awayTeam").equals(awayTeam)) {
    						Common.logOut("ISN找到比赛:" + event.toString());
    						find = true;
    						break;
    					}
    				}
    				if(find == true) {
    					break;
    				}
    			}

    			
    			//开始投注
    			double biggestRatio = 0.0;
    			int betPankou = 1;
    			boolean nomatchratio = false;
    			if(find == true) {
    				JSONArray markets = event.getJSONArray("markets");
    				//红牌判断
    				
//    				if(SpecialServer.mainWnd.getIgnoreRedcard()==false) {
//        				if(updown.equals("1") && event.getInt("homeRedCards") > 0) {
//        					returnRes.put("success", false);
//                    		returnRes.put("responseMessage", "红牌，不投注");
//                    		return returnRes.toString(); 
//        				}
//        				if(!updown.equals("1") && event.getInt("awayRedCards") > 0) {
//        					returnRes.put("success", false);
//                    		returnRes.put("responseMessage", "红牌，不投注");
//                    		return returnRes.toString(); 
//        				}
//    				}
    				

    				
    				if(markets.length() == 0) {
    					map.put("status", "2");
    					return map;
    				}
    				for(int i = 0; i < markets.length(); i++) {
    					JSONObject market = markets.getJSONObject(i);
    					if(market.getString("name").equals(marketName)) {
    						JSONArray lines = market.getJSONArray("lines");
    						//j = 0 盘口1  j =1 盘口2
    						for(int j = 0; j < lines.length(); j++) {
    							JSONObject line = lines.getJSONObject(j);
    							JSONArray marketSelections = line.getJSONArray("marketSelections");
 
        							for(int k = 0; k < marketSelections.length(); k++) {
        								JSONObject marketSelection = marketSelections.getJSONObject(k);
        								if(marketSelection.getString("indicator").equals(betIndicator)) {
        									double odds = marketSelection.getDouble("odds");
        									double pankou = marketSelection.getDouble("handicap");
        									if(updown.contains("1")&&betIndicator.equals("Home")) {
        										pankou = 0.0 - pankou;
        									}        									        									        								
        									
        									if(Math.abs(pankou-pankouarg)>0.01)
        									{
        										Common.logOut("盘口未对上，继续看下一个盘口:" + pankou + "   " + pankouarg);
        										continue;//盘口不对，继续找
        									}
        									
        									if(odds < 0) {
        										odds = 2.0 + odds;
        									}
        									

        									
        									//if(odds >= ratio){
        										nomatchratio = false;
        										//投注
        										
        										String betLimiturl = ADDRESS + "membersite-api/api/bet/limit/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
        										
        										String betLimitres = doGet(betLimiturl, "", "", token);
        										
        										if(betLimitres == null) {
        											betLimitres = doGet(betLimiturl, "", "", token);
        										}
        										
        										Common.logOut("betLimitres:" + betLimitres);
        										
        										if(betLimitres != null && betLimitres.contains("成功")) {        											
        											JSONObject betlimitjb = new JSONObject(betLimitres);
        											int maxBet = betlimitjb.getInt("maxBet");
        											if(maxBet < gold) {
        												gold = maxBet;
        											}
        											
            										String detailUrl = ADDRESS + "membersite-api/api/bet/ticket/detail/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
            										String detailres = doGet(detailUrl, "", "", token);
            							    		
            							    		if(detailres == null) {
            							    			detailres = doGet(detailUrl, "", "", token);
            							    		}
            							    		
            							    		Common.logOut("detailres:" + detailres);
            							    		
            							    		
            							    		if(detailres != null && detailres.contains("betTicket")) {
            							    			JSONObject detailjb = new JSONObject(detailres);
            							    			if(detailjb.getBoolean("success") == true) {
            							    				JSONObject betTicket = detailjb.getJSONObject("betTicket");            							    				
            							    				Common.logOut("ISN EVENT:" + event.getString("name"));            							    				
            							    				String betUrl = ADDRESS + "membersite-api/api/bet/placeInPlayBet";
            							    				if(bettype.contains("单式")) {
            							    					betUrl = ADDRESS + "membersite-api/api/bet/placeBet";
            							    				}            							    				
            							    				JSONObject betparam = new JSONObject();
            							    				betparam.put("acceptHigherOdds", true);
            							    				betparam.put("decimalOdds", betTicket.getString("decimalOdds"));
            							    				betparam.put("eventPitcherId", betTicket.getInt("eventPitcherId"));
            							    				betparam.put("handicap", betTicket.getString("handicap"));
            							    				betparam.put("marketSelectionId", betTicket.getLong("marketSelectionId"));
            							    				betparam.put("odds", betTicket.getString("odds"));
            							    				betparam.put("oddsFormatId", betTicket.getInt("oddsFormatId"));
            							    				betparam.put("requestId", System.currentTimeMillis());
            							    				if(bettype.contains("滚球")) {
            							    					betparam.put("score", betTicket.getString("score"));
            							    				}            							    				
            							    				betparam.put("stake", gold);
            							    				String betres = doPost(betUrl, betparam.toString(), token);
            							    				
            							    				Common.logOut("betres:" + betres);
            							    				
            							    				if((betres.contains("市场更新中。请重试")||betres.contains("赔率已更改"))&&inrecursiontimes<=2) {
            							    					Thread.sleep(2000);
            							    					//直接递归调用     
            							    					Common.logOut("进入递归:" + inrecursiontimes);
            							    					return dobet( homeTeam,  awayTeam,  updown,  bettype,  gold,  pankouarg, ratio,  inrecursiontimes++);
//            							    					detailUrl = ADDRESS + "membersite-api/api/bet/ticket/detail/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
//                        										detailres = doGet(detailUrl, "", "", token);
//                        							    		
//                        							    		if(detailres == null) {
//                        							    			detailres = doGet(detailUrl, "", "", token);
//                        							    		}
//                        							    		
//                        							    		if(detailres != null && detailres.contains("betTicket")) {
//                        							    			detailjb = new JSONObject(detailres);
//                        							    			if(detailjb.getBoolean("success") == true) {
//                        							    				betTicket = detailjb.getJSONObject("betTicket");            							    				
//                        							    				Common.logOut("ISN EVENT:" + event.getString("name"));            							    				
//                        							    				betUrl = ADDRESS + "membersite-api/api/bet/placeInPlayBet";
//                        							    				if(bettype.contains("单式")) {
//                        							    					betUrl = ADDRESS + "membersite-api/api/bet/placeBet";
//                        							    				}            							    				
//                        							    				betparam = new JSONObject();
//                        							    				betparam.put("acceptHigherOdds", true);
//                        							    				betparam.put("decimalOdds", betTicket.getString("decimalOdds"));
//                        							    				betparam.put("eventPitcherId", betTicket.getInt("eventPitcherId"));
//                        							    				betparam.put("handicap", betTicket.getString("handicap"));
//                        							    				betparam.put("marketSelectionId", betTicket.getLong("marketSelectionId"));
//                        							    				betparam.put("odds", betTicket.getString("odds"));
//                        							    				betparam.put("oddsFormatId", betTicket.getInt("oddsFormatId"));
//                        							    				betparam.put("requestId", System.currentTimeMillis());
//                        							    				if(bettype.contains("滚球")) {
//                        							    					betparam.put("score", betTicket.getString("score"));
//                        							    				}            							    				
//                        							    				betparam.put("stake", gold);
//                        							    				betres = doPost(betUrl, betparam.toString(), token);
//                        							    				
//                        							    				Common.logOut("重试 betres:" + betres);
//                        							    			}
//                        							    		}
                        							    		
            							    				}
            							    				
            							    				if(betres.contains("betDate")) {
            							    					JSONObject betresjb = new JSONObject(betres);
            							    					if(betresjb.getBoolean("success") == true) {
            							    						JSONObject betinfojb = betresjb.getJSONObject("betInfo");
            							    						map.put("status", "1");
            							    						map.put("wagerId", Long.toString(betinfojb.getLong("betId")));
            							    						map.put("ratio", betinfojb.getString("odds"));
            							    						map.put("stake", Integer.toString(betinfojb.getInt("stake")));
            							    						
            							    						return map;
            							    						
            							    					}else {
            							    						map.put("status", "2");
                							    			    	return map;
            							    					}

            							    				}else {
            							    					map.put("status", "2");
            							    			    	return map;
            							    				}
            							    				
            							    			}
            							    		}
        											
        										}else if(betLimitres != null && betLimitres.contains("还未开投")){
        											Common.logOut("[赛事/市场/选项] 还未开投");
        											map.put("status", "2");
							    			    	return map;
        										}
        										

        									//}//符合水位区域
        									
        								}//if 区域
        							}//for循环
    								
        							//retryTimes++;
        							
//        							if(nomatchratio) {
//        			            		returnRes.put("success", false);
//        			            		returnRes.put("responseMessage", "水位不符.最高水位" + Integer.toString(betPankou) + "盘:" + Double.toString(biggestRatio));
//        			            		Common.logOut(event);
//        			            		return returnRes.toString(); 
//        			    			}
        							
        							
    							//}//while循环
    							

    						}
    						
							
    						
    					}
    				}
    			}else {
    				Common.logOut("ISN未找到相应球赛");
    				map.put("status", "2");
			    	return map;

    			}
    			
    			
    			

    		}else {
    			Common.logOut("无法获取赛事列表");
				map.put("status", "2");
		    	return map;

    		}
    		
    	}catch(Exception e) {
    		e.printStackTrace();
			Common.logOut("投注异常");
			map.put("status", "2");
	    	return map;
    		
    		
    		
    		
    	}
    	
    	
    	map.put("status", "2");
    	return map;
    }

    public Map<String, String> updateISNRatio(String homeTeam, String awayTeam, String updown, String bettype,
			Double pankouarg) {

    	try {
    		
    		Map<String, String> map = new HashMap<String, String>();
    		
    		String eventsUrl = ADDRESS + "membersite-api/api/data/events/1/3/0/4/3?_=" + Long.toString(System.currentTimeMillis());    	
    		if(bettype.contains("单式")) {
    			eventsUrl = ADDRESS + "membersite-api/api/data/events/1/2/0/4/3?_=" + Long.toString(System.currentTimeMillis());
    		}
    		String res = doGet(eventsUrl, "", "", token);    		
    		if(res == null) {
    			res = doGet(eventsUrl, "", "", token);
    		}    		
    		String marketName = "";
    		if(bettype.contains("单式")&&bettype.contains("让球")) {
    			marketName = "让球";
    		}else if(bettype.contains("滚球")&&bettype.contains("让球")) {
    			marketName = "滚球让球";
    		}else if(bettype.contains("单式")&&bettype.contains("全场大小")) {
    			marketName = "大小";
    		}else if(bettype.contains("单式")&&bettype.contains("半场大小")) {
    			marketName = "半场大小";
    		}else if(bettype.contains("滚球")&&bettype.contains("全场大小")) {
    			marketName = "滚球大小";
    		}else if(bettype.contains("滚球")&&bettype.contains("半场大小")) {
    			marketName = "半场滚球大小";
    		}
    		
    		String betIndicator = "Home";
    		
    		if(bettype.contains("让球")) {
    			if(updown.equals("1")) {
        			betIndicator = "Home";
        		}else {
        			betIndicator = "Away";
        		}
    		}else if(bettype.contains("大小")) {
    			if(updown.equals("1")) {
        			betIndicator = "Over";
        		}else {
        			betIndicator = "Under";
        		}
    		}
    		
    		
    		
    		
    		
    		if(res != null && res.contains("schedule")) {
    			JSONObject inplayRes = new JSONObject(res);
    			JSONArray leagues = inplayRes.getJSONObject("schedule").getJSONArray("leagues");
    			//遍历jsonarray
    			JSONObject event = null;
    			boolean find = false;
    			for(int i = 0; i< leagues.length(); i++) {
    				JSONObject league = leagues.getJSONObject(i);
    				JSONArray events = league.getJSONArray("events");
    				for(int j = 0 ; j < events.length(); j++) {
    					event = events.getJSONObject(j);
    					if(event.getString("homeTeam").equals(homeTeam) && event.getString("awayTeam").equals(awayTeam)) {
    						Common.logOut("ISN找到比赛:" + event.toString());
    						find = true;
    						break;
    					}
    				}
    				if(find == true) {
    					break;
    				}
    			}
    			
    			//开始投注
    			double biggestRatio = 0.0;
    			int betPankou = 1;
    			boolean nomatchratio = false;
    			if(find == true) {
    				JSONArray markets = event.getJSONArray("markets");
    				//红牌判断
    				
//    				if(SpecialServer.mainWnd.getIgnoreRedcard()==false) {
//        				if(updown.equals("1") && event.getInt("homeRedCards") > 0) {
//        					returnRes.put("success", false);
//                    		returnRes.put("responseMessage", "红牌，不投注");
//                    		return returnRes.toString(); 
//        				}
//        				if(!updown.equals("1") && event.getInt("awayRedCards") > 0) {
//        					returnRes.put("success", false);
//                    		returnRes.put("responseMessage", "红牌，不投注");
//                    		return returnRes.toString(); 
//        				}
//    				}
    				

    				
    				if(markets.length() == 0) {
    					Common.logOut("无投注盘口");
    					return null;
    				}
    				for(int i = 0; i < markets.length(); i++) {
    					JSONObject market = markets.getJSONObject(i);
    					if(market.getString("name").equals(marketName)) {
    						JSONArray lines = market.getJSONArray("lines");
    						//j = 0 盘口1  j =1 盘口2
    						for(int j = 0; j < lines.length(); j++) {
    							JSONObject line = lines.getJSONObject(j);
    							JSONArray marketSelections = line.getJSONArray("marketSelections");
 
        							for(int k = 0; k < marketSelections.length(); k++) {
        								JSONObject marketSelection = marketSelections.getJSONObject(k);
        								if(marketSelection.getString("indicator").equals(betIndicator)) {
        									double odds = marketSelection.getDouble("odds");
        									double pankou = marketSelection.getDouble("handicap");
        									if(updown.contains("1")&&betIndicator.equals("Home")) {
        										pankou = 0.0 - pankou;
        									}        									        									        								
        									
        									if(Math.abs(pankou-pankouarg)>0.01)
        									{
        										Common.logOut("盘口未对上，继续看下一个盘口:" + pankou + "   " + pankouarg);
        										continue;//盘口不对，继续找
        									}
        									
        									if(odds < 0) {
        										odds = 2.0 + odds;
        									}
        									

        									
        									//if(odds >= ratio){
        										
        										//投注
        										
        										String betLimiturl = ADDRESS + "membersite-api/api/bet/limit/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
        										
        										String betLimitres = doGet(betLimiturl, "", "", token);
        										
        										if(betLimitres == null) {
        											betLimitres = doGet(betLimiturl, "", "", token);
        										}
        										
        										Common.logOut("betLimitres:" + betLimitres);
        										
        										if(betLimitres != null && betLimitres.contains("成功")) {        											
        											JSONObject betlimitjb = new JSONObject(betLimitres);
        											int maxBet = betlimitjb.getInt("maxBet");
        											int minBet = betlimitjb.getInt("minBet");
        											map.put("maxbet", Integer.toString(maxBet));
        											map.put("minbet", Integer.toString(minBet));
        											
            										String detailUrl = ADDRESS + "membersite-api/api/bet/ticket/detail/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
            										String detailres = doGet(detailUrl, "", "", token);
            							    		
            							    		if(detailres == null) {
            							    			detailres = doGet(detailUrl, "", "", token);
            							    		}
            							    		
            							    		Common.logOut("detailres:" + detailres);
            							    		
            							    		
            							    		if(detailres != null && detailres.contains("betTicket")) {
            							    			JSONObject detailjb = new JSONObject(detailres);
            							    			if(detailjb.getBoolean("success") == true) {
            							    				JSONObject betTicket = detailjb.getJSONObject("betTicket");            							    				
            							    				Common.logOut("ISN EVENT:" + event.getString("name"));            							    				
            							    				        							    				
//            							    				JSONObject betparam = new JSONObject();
//            							    				betparam.put("acceptHigherOdds", true);
//            							    				betparam.put("decimalOdds", betTicket.getString("decimalOdds"));
//            							    				betparam.put("eventPitcherId", betTicket.getInt("eventPitcherId"));
//            							    				betparam.put("handicap", betTicket.getString("handicap"));
//            							    				betparam.put("marketSelectionId", betTicket.getLong("marketSelectionId"));
//            							    				betparam.put("odds", betTicket.getString("odds"));
//            							    				betparam.put("oddsFormatId", betTicket.getInt("oddsFormatId"));
//            							    				betparam.put("requestId", System.currentTimeMillis());
            							    				
            							    				map.put("ratio", betTicket.getString("odds"));
            							    				map.put("marketSelectionId", Long.toString(betTicket.getLong("marketSelectionId")));
            							    				return map;
            							    			}
            							    		}
        											
        										}else if(betLimitres != null && betLimitres.contains("还未开投")){
        											Common.logOut("还未开投");
        											
        										}
        										

        									//}//符合水位区域
        									
        								}//if 区域
        							}//for循环
    								
        							//retryTimes++;
        							
//        							if(nomatchratio) {
//        			            		returnRes.put("success", false);
//        			            		returnRes.put("responseMessage", "水位不符.最高水位" + Integer.toString(betPankou) + "盘:" + Double.toString(biggestRatio));
//        			            		Common.logOut(event);
//        			            		return returnRes.toString(); 
//        			    			}
        							
        							
    							//}//while循环
    							

    						}
    						
							
    						
    					}
    				}
    			}else {
            		Common.logOut("ISN未找到相应球赛");
            		
    			}
    			
    			
    			

    		}else {
    			Common.logOut("无法获取赛事列表");
    		}
    		
    	}catch(Exception e) {
    		e.printStackTrace();
    		return null;
    	}
    	return null;
	}
	

    public String dobetdxq(String homeTeam, String awayTeam, String updown, double ratio, int gold, Vector<Double> hgpankous) {
    	
    	JSONObject returnRes = new JSONObject();
    	
    	if(hgpankous==null) {
			returnRes.put("success", false);
    		returnRes.put("responseMessage", "皇冠投注盘口为空");
    		return returnRes.toString(); 
    	}
    	    	
    	try {
    		
    		String inplayUrl = ADDRESS + "membersite-api/api/data/events/1/3/0/4/3?_=" + Long.toString(System.currentTimeMillis());    		
    		String res = doGet(inplayUrl, "", "", token);
    		
    		if(res == null) {
    			res = doGet(inplayUrl, "", "", token);
    		}
    		
    		String betIndicator = "Over";
    		if(updown.equals("1")) {
    			betIndicator = "Over";
    		}else {
    			betIndicator = "Over";
    		}
    		
    		
    		
    		if(res != null && res.contains("schedule")) {
    			JSONObject inplayRes = new JSONObject(res);
    			JSONArray leagues = inplayRes.getJSONObject("schedule").getJSONArray("leagues");
    			//遍历jsonarray
    			JSONObject event = null;
    			boolean find = false;
    			for(int i = 0; i< leagues.length(); i++) {
    				JSONObject league = leagues.getJSONObject(i);
    				String leaguename = league.getString("name");
    				JSONArray events = league.getJSONArray("events");
    				for(int j = 0 ; j < events.length(); j++) {
    					event = events.getJSONObject(j);
    					if(event.getString("homeTeam").equals(homeTeam) && event.getString("awayTeam").equals(awayTeam)) {
    						Common.logOut("ISN找到比赛:" + event.toString());
    						find = true;
    						break;
    					}
    				}
    				if(find == true) {
    					break;
    				}
    			}
    			
    			int retryTimes = 0;
    			
    			//开始投注
    			double biggestRatio = 0.0;
    			int betPankou = 1;
    			boolean nomatchratio = false;
    			if(find == true) {
    				JSONArray markets = event.getJSONArray("markets");
    				
    				if(markets.length() == 0) {
    					returnRes.put("success", false);
                		returnRes.put("responseMessage", "无投注盘口");
                		return returnRes.toString(); 
    				}
    				for(int i = 0; i < markets.length(); i++) {
    					JSONObject market = markets.getJSONObject(i);
    					if(market.getString("name").equals("大小") || market.getString("name").equals("滚球大小")) {
    						JSONArray lines = market.getJSONArray("lines");
    						//j = 0 盘口1  j =1 盘口2
    						for(int j = 0; j < lines.length(); j++) {
    							JSONObject line = lines.getJSONObject(j);
    							JSONArray marketSelections = line.getJSONArray("marketSelections");
    							
    							//while(retryTimes < 3) {
    								
    								
        							for(int k = 0; k < marketSelections.length(); k++) {
        								JSONObject marketSelection = marketSelections.getJSONObject(k);
        								if(marketSelection.getString("indicator").equals(betIndicator)) {
        									double odds = marketSelection.getDouble("odds");
        									double pankou = marketSelection.getDouble("handicap");
        									
        									        									
        									if(!hgpankous.contains(pankou)) {
        										Common.logOut("hg12大小盘无该盘口:" + pankou);
        										for(int kkk = 0; kkk< hgpankous.size();kkk++) {
        											Common.logOut("hg" +(kkk+1) + "盘口:" + hgpankous.elementAt(kkk));
        										}
        										continue;
        									}
        									
        									if(odds < 0) {
        										odds = 2.0 + odds;
        									}
        									
        									
        									
        									if(biggestRatio < odds) {
        										biggestRatio = odds;
        										betPankou = j + 1;
        									}
        									
        									if(biggestRatio < ratio) {
        										nomatchratio = true;
        									}
        									
        									if(odds >= ratio){
        										nomatchratio = false;
        										//投注
        										
        										String betLimiturl = ADDRESS + "membersite-api/api/bet/limit/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
        										
        										String betLimitres = doGet(betLimiturl, "", "", token);
        										
        										if(betLimitres == null) {
        											betLimitres = doGet(betLimiturl, "", "", token);
        										}
        										
        										Common.logOut("betLimitres:" + betLimitres);
        										
        										if(betLimitres != null && betLimitres.contains("成功")) {
        											
        											JSONObject betlimitjb = new JSONObject(betLimitres);
        											int maxBet = betlimitjb.getInt("maxBet");
        											if(maxBet < gold) {
        												gold = maxBet;
        											}
        											
            										String detailUrl = ADDRESS + "membersite-api/api/bet/ticket/detail/" + Long.toString(marketSelection.getLong("id")) + "/4/3?_=" + Long.toString(System.currentTimeMillis());
            										String detailres = doGet(detailUrl, "", "", token);
            							    		
            							    		if(detailres == null) {
            							    			detailres = doGet(detailUrl, "", "", token);
            							    		}
            							    		
            							    		Common.logOut("detailres:" + detailres);
            							    		
            							    		
            							    		if(detailres != null && detailres.contains("betTicket")) {
            							    			JSONObject detailjb = new JSONObject(detailres);
            							    			if(detailjb.getBoolean("success") == true) {
            							    				JSONObject betTicket = detailjb.getJSONObject("betTicket");
            							    				
            							    				Common.logOut("ISN EVENT:" + event.getString("name"));
            							    				
            							    				String betUrl = ADDRESS + "membersite-api/api/bet/placeInPlayBet";
            							    				//String betUrl = ADDRESS + "membersite-api/api/bet/placeBet";
            							    				JSONObject betparam = new JSONObject();
            							    				betparam.put("acceptHigherOdds", true);
            							    				betparam.put("decimalOdds", betTicket.getString("decimalOdds"));
            							    				betparam.put("eventPitcherId", betTicket.getInt("eventPitcherId"));
            							    				betparam.put("handicap", betTicket.getString("handicap"));
            							    				betparam.put("marketSelectionId", betTicket.getLong("marketSelectionId"));
            							    				betparam.put("odds", betTicket.getString("odds"));
            							    				betparam.put("oddsFormatId", betTicket.getInt("oddsFormatId"));
            							    				betparam.put("requestId", System.currentTimeMillis());
            							    				betparam.put("score", betTicket.getString("score"));
            							    				betparam.put("stake", gold);
            							    				String betres = doPost(betUrl, betparam.toString(), token);
            							    				
            							    				Common.logOut("betres:" + betres);
            							    				
            							    				
            							    				if(betres.contains("betDate")) {
            							    					JSONObject betresjb = new JSONObject(betres);
            							    					if(betresjb.getBoolean("success") == true) {
            							    						returnRes.put("success", true);
            							    						returnRes.put("responseMessage", betresjb.getString("responseMessage"));
            							    						
            							    						JSONObject betinfojb = betresjb.getJSONObject("betInfo");
            							    						
            							    						returnRes.put("betDate", betinfojb.getLong("betDate"));
            							    						returnRes.put("betId",  betinfojb.getLong("betId"));
            							    						returnRes.put("odds", betinfojb.getString("odds"));
            							    						returnRes.put("pankou", betinfojb.getString("handicap"));
            							    						returnRes.put("stake", betinfojb.getInt("stake"));
            							    						returnRes.put("score", betTicket.getString("score"));
            							    						if(betIndicator.equals("Over")) {
            							    							returnRes.put("betTeam", "大"); 
            							    						}else {
            							    							returnRes.put("betTeam", "大");
            							    						}
            							    						
            							    						return returnRes.toString();
            							    						
            							    					}else {
            							    						returnRes.put("success", false);
                							    					returnRes.put("responseMessage", betresjb.getString("responseMessage"));
                							    			    	if(betresjb.getString("responseMessage").contains("市场更新中")) {
                							    			    		Common.logOut("ISN尝试重新投注");
                							    			    		Thread.sleep(2000);	
                							    			    		j = -1;
                							    			    		break;
                							    			    	}else {
                							    			    		return returnRes.toString();
                							    			    	}
                							    			    	
            							    					}

            							    				}else {
            							    					returnRes.put("success", false);
            							    					returnRes.put("responseMessage", "投注失败");
            							    			    	Common.logOut("ISN投注失败:" + betres);
            							    			    	return returnRes.toString();
            							    				}
            							    				
            							    			}
            							    		}
        											
        										}else if(betLimitres != null && betLimitres.contains("还未开投")){
        											returnRes.put("success", false);
							    					returnRes.put("responseMessage", "[赛事/市场/选项] 还未开投");
							    					return returnRes.toString();
        										}
        										

        									}//符合水位区域
        									
        								}//if 区域
        							}//for循环
    								
        							//retryTimes++;
        							
//        							if(nomatchratio) {
//        			            		returnRes.put("success", false);
//        			            		returnRes.put("responseMessage", "水位不符.最高水位" + Integer.toString(betPankou) + "盘:" + Double.toString(biggestRatio));
//        			            		Common.logOut(event);
//        			            		return returnRes.toString(); 
//        			    			}
        							
        							
    							//}//while循环
    							

    						}
    						
							if(nomatchratio) {
			            		returnRes.put("success", false);
			            		returnRes.put("responseMessage", "水位不符.最高水位" + Integer.toString(betPankou) + "盘:" + Double.toString(biggestRatio));
			            		Common.logOut("水位不符:" + event);
			            		return returnRes.toString(); 
			    			}
    						
    					}
    				}
    			}else {
            		returnRes.put("success", false);
            		returnRes.put("responseMessage", "ISN未找到相应球赛");
            		return returnRes.toString(); 
    			}
    			
    			
    			

    		}else {
        		returnRes.put("success", false);
        		returnRes.put("responseMessage", "无法获取赛事列表");
        		return returnRes.toString();
    		}
    		
    	}catch(Exception e) {
    		returnRes.put("success", false);
    		returnRes.put("responseMessage", "投注异常");
    		updateStatusCode(-1);
    		
    		e.printStackTrace();
    		return returnRes.toString();
    	}
    	
    	
		returnRes.put("success", false);
		returnRes.put("responseMessage", "投注失败");
    	
    	return returnRes.toString();
    }
    
    
    
    
    public   void addFailsTimes(){
    	
    	Common.logOut("add failed times");
    	
    	long currentTime = System.currentTimeMillis();
    	
    	if(((currentTime - lastFailtime) < 40*1000) || (lastFailtime == 0)){
    		requestFailTimes++;
    		
    		lastFailtime = currentTime;
    		
    		if(requestFailTimes >= 4){
    			Common.logOut("request fail times big than 4");    			
    			setIsNeedRelogin(true);
    			requestFailTimes = 0;
    			
    			
    			
    			
    		}
    		
    	}
    	else{
    		requestFailTimes = 1;
    		lastFailtime = currentTime;
    	}
    }
    
    
    public   void setIsNeedRelogin(boolean flag){
    	
    	Common.logOut("set need relogin");
    	
    	isNeedRelogin = flag;
    	requestFailTimes = 0;
    	token = "";
    	
    	updateStatusCode(-1);
    	
    	
    }
    
    public   boolean getIsNeedRelogin(){
    	return isNeedRelogin;
    }

	public void updatehgBetLogData(Vector<BetAdyData> specialBetLogDatas) {
		
		//http://isn99.com/membersite-api/api/bet/list/lastTenOpenAndPending?_=1573269148921
		
		try {
			String url = ADDRESS + "membersite-api/api/bet/list/lastTenOpenAndPending?_=" + Long.toString(System.currentTimeMillis());
			String res = doGet(url,"", "", token);
			if(res == null) {
				res =  doGet(url,"", "", token);
			}
			if(res != null && res.contains("lastTenOpenBets")) {
				JSONObject jb = new JSONObject(res);
				JSONArray lastTenOpenBets = jb.getJSONArray("lastTenOpenBets");
				for(BetAdyData bd: specialBetLogDatas) {
					for(int j = 0; j< lastTenOpenBets.length(); j++) {
						JSONObject openBet = lastTenOpenBets.getJSONObject(j);
						if(Long.toString(openBet.getLong("betId")).equals(bd.gid)) {
							bd.hgbetres = "2";
						}
					}
				}
				
			}else {
				addFailsTimes();
			}
			
		}catch(Exception e) {
			e.printStackTrace();			
		}
		
	}


	public void getbalance() {
		// TODO Auto-generated method stub
		
//		String inplayUrl = ADDRESS + "membersite-api/api/member/info?_=" + Long.toString(System.currentTimeMillis());    		
//		String res = doGet(inplayUrl, "", "", token);
//		if(res!=null&&res.contains("betCredit")) {
//			Common.logOut(ACCOUNT+"在线");
//		}else {
//			Common.logOut(ACCOUNT+"掉线重登");
//			updateStatusCode(-1);
//		}
		
		
		
		
		
    	try{
        	String url = ADDRESS + "membersite-api/api/member/info?_=" + Long.toString(System.currentTimeMillis());
        	String res = doGet(url, "", "", token);
        	if(res != null && res.contains("betCredit")) {
        		JSONObject jb = new JSONObject(res);
        		double balance = jb.getDouble("betCredit");
        		//Common.logOut(ACCOUNT+"在线");
        		DecreaseRatioClient.mainWnd.updateISNAccountBalance(ACCOUNT, Double.toString(balance));
        		DecreaseRatioClient.mainWnd.updateMainWndSpecialHGStatusText(1,  "在线");
        	}else {
        		Common.logOut("ISN getBalance");
        		Common.logOut(res);
        		updateStatusCode(-1);
        	}
    	}catch(Exception e) {
    		Common.logOut(ACCOUNT+"掉线重登");
    		updateStatusCode(-1);
    		e.printStackTrace();
    	}
		
		
	}

	
    

    
    
}
